﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Collision.Shapes;
using Microsoft.Xna.Framework;

namespace KinectBender
{
    class Particle
    {
        #region Fields
        
        CircleShape shape;
        
        Fixture fixture;

        #endregion
        
        #region Properties

        public World World { get; private set; }

        public Body Body { get; private set; }
        
        public Vector2 Position
        {
            get
            {
                return Body.Position;
            }
            set
            {
                Body.Position = value;
            }
        }

        private float _radius = .1f;
        public float Radius
        {
            get
            {
                return _radius;
            }
            set
            {
                _radius = value;
                if (shape != null)
                    shape.Radius = value;
            }
        }

        #endregion

        #region Constructors

        public Particle(World world, float radius)
        {
            this.World = world;
            this.Radius = radius;
            Init();
        }

        #endregion

        #region Public Methods

        #endregion

        #region Private Methods

        private void Init()
        {
            Body = new Body(World);
            Body.BodyType = BodyType.Dynamic;

            shape = new CircleShape(Radius, 1f);
            fixture = Body.CreateFixture(shape);
            fixture.Friction = 0.0f;
            fixture.Restitution = 0.5f;

            Body.FixedRotation = true;
            World.BodyList.Add(Body);
        }

        #endregion
    }
}
